package th.retrofit.lib;

import java.util.HashSet;

public class Solution2063 {

    public long countVowels(String word) {
        HashSet<Character> set = new HashSet<>();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');
        int wLen = word.length();
        int pre = 0;
        long[] dp = new long[wLen];
        for (int i = 0; i < wLen; i++) {
            if (set.contains(word.charAt(i))) {
                pre += 1;
            }
            dp[0] += pre;
        }
        long totalCount = dp[0];
        for (int i = 1; i < wLen; i++) {
            if (set.contains(word.charAt(i - 1))) {
                dp[i] = dp[i - 1] - (wLen - (i - 1));
            } else {
                dp[i] = dp[i - 1];
            }
            totalCount += dp[i];
        }
        return totalCount;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2063().countVowels("aba"));
    }
}
